package eu.jpereira.trainings.designpatterns.creational.builder;

import java.util.Iterator;

import eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBody;
import eu.jpereira.trainings.designpatterns.creational.builder.model.SaleEntry;
import eu.jpereira.trainings.designpatterns.creational.builder.model.SoldItem;

public class HTMLReportBody implements ReportBody {

	private StringBuffer delegate = new StringBuffer();
	/*public HTMLReportBody() {
		delegate = new StringBuffer();
	}*/

	@Override
	public void putContent(SaleEntry content) {
		
		addContent("<span class=\"customerName\">");
		addContent(content.getCustomer().getName());
		addContent("</span><span class=\"customerPhone\">");
		addContent(content.getCustomer().getPhone());
		addContent("</span>");
		
		addContent("<items>");
		
		Iterator<SoldItem> it = content.getSoldItems().iterator();
		while ( it.hasNext() ) {
			SoldItem soldEntry= it.next();
			addContent("<item><name>");
			addContent(soldEntry.getName());
			addContent("</name><quantity>");
			addContent(soldEntry.getQuantity());
			addContent("</quantity><price>");
			addContent(soldEntry.getUnitPrice());
			addContent("</price></item>");
		}
		addContent("</items>");
	}
	public void addContent(Object content) {
		this.delegate.append(content);
		
	}
	@Override
	public Object getAsString() {
		return this.delegate.toString();
	}


		
}
